/********************************************************************************
 * PrivateMailOptionsAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Sep 8, 2008 11:45:05 AM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/

package com.printeverywhere.action;

import java.sql.BatchUpdateException;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

import com.printeverywhere.delegator.PrivateMailOptionsServiceDelegator;
import com.printeverywhere.dto.PrivateMailOption;
import com.printeverywhere.util.AdminConstants;

/**
 * The Class PrivateMailOptionsAction.
 */
public class PrivateMailOptionsAction  extends AdminSystemSetup {

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(PrivateMailOptionsAction.class);

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The private mail option. */
	private PrivateMailOption privateMailOption;

	/**
	 * Gets the private mail option.
	 *
	 * @return the private mail option
	 */
	public PrivateMailOption getPrivateMailOption() {
		return privateMailOption;
	}

	/**
	 * Sets the private mail option.
	 *
	 * @param privateMailOption the new private mail option
	 */
	public void setPrivateMailOption(PrivateMailOption privateMailOption) {
		this.privateMailOption = privateMailOption;
	}

	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception{
		if (logger.isDebugEnabled()) {
			logger.debug("execute() - start"); //$NON-NLS-1$
		}

		this.privateMailOption = PrivateMailOptionsServiceDelegator.getPrivateMailOptions();

		if (logger.isDebugEnabled()) {
			logger.debug("execute() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Update private mail options.
	 *
	 * @return the string
	 *
	 * @throws Exception the exception
	 */
	public String updatePrivateMailOptions() throws HibernateException{
		if (logger.isDebugEnabled()) {
			logger.debug("updatePrivateMailOptions() - start"); //$NON-NLS-1$
		}
		try{
			PrivateMailOptionsServiceDelegator.updatePrivateMailOptions(privateMailOption);
			addActionMessage("Private mail option configuation has been successfully changed.");
		}catch (HibernateException e) {
			addActionError("Enter proper data.");
			logger.info(AdminConstants.RECORD_NOT_UPDATED+e);
			return INPUT;
		}catch(Exception e){
			addActionError("Enter proper data.");
			logger.info(AdminConstants.RECORD_NOT_UPDATED+e);
			return INPUT;
		}

		if (logger.isDebugEnabled()) {
			logger.debug("updatePrivateMailOptions() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}
}